package business;

import business.database.Database;
import business.iservices.BusinessSrv;
import business.iservices.IDataBasesService;
import result.Result;

/**
 * Servicios para gestionar las bases de datos
 * @author 53385255R
 *
 */
public class DataBasesService extends BusinessSrv implements IDataBasesService {

	
	/**
	 * @see business.iservices.IDataBasesService#setSQLite(java.lang.String)
	 */
	@Override
	public Result<Object> setSQLite(String path) {
		Result<Object> res = new Result<Object>("", null,  false);
		try {
			Database.getInstance().setSqlite(path);
			res.set_ok(true);
			
		} catch (Exception e) {
			ViewLogger.getInstance().error("No se ha podido iniciar la base de datos SQLite");
		}
		
		return res;
	}
	
	/**
	 * @see business.iservices.IDataBasesService#closeAll()
	 */
	@Override
	public Result<Object> closeAll() {
		Result<Object> res = new Result<Object>("", null,  true);
		
		Database.getInstance().closeAll();
		
		return res;
	}

	/**
	 * @see business.iservices.IDataBasesService#setMaescorp(java.lang.String)
	 */
	@Override
	public Result<Object> setMaescorp(String path) {
		Result<Object> res = new Result<Object>("", null,  false);
		try {
			Database.getInstance().setMaescorp(path);
			res.set_ok(true);
			
		} catch (Exception e) {
			ViewLogger.getInstance().error("No se ha podido iniciar la base de datos Maescorp");
		}
		
		return res;
	}

	/**
	 * @see business.iservices.IDataBasesService#setNewCorps(java.lang.String)
	 */
	@Override
	public Result<Object> setNewCorps(String path) {
		Result<Object> res = new Result<Object>("", null,  false);
		try {
			Database.getInstance().setNewCorps(path);
			res.set_ok(true);
			
		} catch (Exception e) {
			ViewLogger.getInstance().error("No se ha podido iniciar la base de datos NewCorps");
		}
		
		return res;
	}


	/**
	 * @see business.iservices.IDataBasesService#setMaesorg(java.lang.String)
	 */
	@Override
	public Result<Object> setMaesorg(String path) {
		Result<Object> res = new Result<Object>("", null,  false);
		try {
			Database.getInstance().setMaesorg(path);
			res.set_ok(true);
			
		} catch (Exception e) {
			ViewLogger.getInstance().error("No se ha podido iniciar la base de datos Maesorg");
		}
		
		return res;
	}




	
	
	
	
	
}
